

#include <assert.h>
#include <unistd.h>
#include <time.h>
/* Default configuration */

#include "TrackerKCFdsp.hpp"

#include "tracker_kcf_dsp_adap.h"


TrackerKCFdsp::TrackerKCFdsp(int img_width, int img_height, int patch_size, bool multiscale): handle(nullptr)
{
    handle = nctid_tracker_kcf_open_session(1);
    nctid_tracker_kcf_init(handle, img_width, img_height, patch_size, multiscale);
}

TrackerKCFdsp::~TrackerKCFdsp()
{
    nctid_tracker_kcf_close_session(handle);
}

void TrackerKCFdsp::update(const cv::Rect& src_roi, cv::Mat src_image, float train_interp_factor, int32_t *dsp_usec)
{
    nctid_roi_t roi;
    roi.x = src_roi.x;
    roi.y = src_roi.y;
    roi.width = src_roi.width;
    roi.height = src_roi.height;
    size_t size = src_image.cols*src_image.rows;
    nctid_tracker_kcf_update(handle, &roi, src_image.data, size, train_interp_factor, dsp_usec);
}

void TrackerKCFdsp::update(const cv::Rect& src_roi, float train_interp_factor, int32_t *dsp_usec)
{
    nctid_roi_t roi;
    roi.x = src_roi.x;
    roi.y = src_roi.y;
    roi.width = src_roi.width;
    roi.height = src_roi.height;
    nctid_tracker_kcf_update2(handle, &roi, train_interp_factor, dsp_usec);
}

cv::Rect TrackerKCFdsp::detect(const cv::Rect& dst_roi, cv::Mat dst_image, float& peak_value, int32_t *dsp_usec)
{
    nctid_roi_t in_roi, out_roi;
    in_roi.x = dst_roi.x;
    in_roi.y = dst_roi.y;
    in_roi.width = dst_roi.width;
    in_roi.height = dst_roi.height;
    size_t size = dst_image.cols*dst_image.rows;
    nctid_tracker_kcf_detect(handle, &in_roi, &out_roi, dst_image.data, size, &peak_value, dsp_usec);
    cv::Rect rect;
    rect.x = out_roi.x;
    rect.y = out_roi.y;
    rect.width = out_roi.width;
    rect.height = out_roi.height;
    return rect;
}

void TrackerKCFdsp::get_debug(void *buf, size_t bufsize)
{
    nctid_tracker_kcf_get_debug(handle, (uint8_t*)buf, bufsize);
}
